define([
	'jquery', 
	'underscore', 
	'backbone', 
	'collections/tweets', 
	'collections/users', 
	'models/user',
	'provider/tweetprovider'
], function($,_,Backbone, Tweets, Users, User, TweetProvider){
	TweetView = Backbone.View.extend({
		el: $("body"),
		tweets: Tweets,
		users: Users,
		initialize: function(){
			console.log("initialize view");
			tweets = new Tweets(null, {view:this});
			users = new Users(null, {view:this});
		},
		events:{
			"click #submit": "submitUser"
		},
		submitUser: function(){
			var username = $("#inputname").val();
			var usermodel = new User();
			usermodel.set({name: username});
			users.add(usermodel);
			console.log("Add new user " + usermodel.get("name"));
			TweetProvider.getTweetPublicProvider(usermodel.get("name"));
		},
		addUser: function(model){
			$("#user").html("User login: "+ model.get("name"));
		},
		addTweet: function(model){
			var tmp = "<li id='"+model.get("id")+"'><a href='#viewdetail/"+model.get("id")+"'>"+
				  "<img src='"+model.get("url")+"'>"+
				  "<h3>"+model.get("name")+"</h3>"+
				  "<p>"+model.get("text")+"</p>"+
			"</a></li>";
			$("#tweet-list").append(tmp);
		}
	});
	return TweetView;
});